<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('出库单列表')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <div class="form-group col-lg-12">
                                    <label class="col-sm-4 control-label">客户:</label>
                                    <div class="input-group">
                                        <input type="text" class="form-control" id="searchCustomer">
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                            </ul>
                                        </div>
                                    </div>
                                    <input type="text" id="customerId" name="customerId" hidden/>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <div class="form-group   col-lg-4">
                        <label class="control-label col-sm-4">出单单号:</label>
                        <div class="input-group">
                            <input type="text" name="rentNumber" class="form-control col-sm-4"   autocomplete="off"/>
                        </div>
                    </div>
                    <div class="form-group col-lg-4">
                        <label class="control-label col-sm-4 ">出单时间:</label>
                        <div class="input-daterange input-group">
                            <input type="text" class="input-sm form-control" id="issueTimeStart"  name="issueTimeStart" autocomplete="off" placeholder="yyyy-MM-dd"/>
                            <span class="input-group-addon">到</span>
                            <input type="text" class="input-sm form-control" id="issueTimeEnd" name="issueTimeEnd" autocomplete="off" placeholder="yyyy-MM-dd"/>
                        </div>
                    </div>
                    <div class="form-group  col-lg-4">
                        <label class="control-label col-sm-4 ">计划开始租赁时间:</label>
                        <div class="input-daterange input-group">
                            <input type="text" class="input-sm form-control" id="planRentStartTimeStart" name="planRentStartTimeStart" autocomplete="off" placeholder="yyyy-MM-dd"/>
                            <span class="input-group-addon">到</span>
                            <input type="text" class="input-sm form-control" id="planRentStartTimeEnd" name="planRentStartTimeEnd" autocomplete="off" placeholder="yyyy-MM-dd"/>
                        </div>
                    </div>
                    <div class="form-group  col-lg-4">
                        <label class="control-label  col-sm-4 ">计划结束租赁时间:</label>
                        <div class="input-daterange input-group">
                            <input type="text" class="input-sm form-control" id="planRentEndTimeStart" name="planRentEndTimeStart" autocomplete="off" placeholder="yyyy-MM-dd"/>
                            <span class="input-group-addon">到</span>
                            <input type="text" class="input-sm form-control" id="planRentEndTimeEnd" name="planRentEndTimeEnd" autocomplete="off" placeholder="yyyy-MM-dd"/>
                        </div>
                    </div>
                    <div class="form-group  col-lg-4">
                        <label class="control-label col-sm-4">实际开始租赁时间:</label>
                        <div class="input-daterange input-group">
                            <input type="text" class="input-sm form-control" id="actualRentStartTimeStart" name="actualRentStartTimeStart" autocomplete="off" placeholder="yyyy-MM-dd"/>
                            <span class="input-group-addon">到</span>
                            <input type="text" class="input-sm form-control" id="actualRentStartTimeEnd" name="actualRentStartTimeEnd" autocomplete="off" placeholder="yyyy-MM-dd"/>
                        </div>
                    </div>
                    <div class="form-group  col-lg-4">
                        <label class="control-label col-sm-4">实际结束租赁时间:</label>
                        <div class="input-daterange input-group">
                            <input type="text" class="input-sm form-control" id="actualRentEndTimeStart"  name="actualRentEndTimeStart" autocomplete="off" placeholder="yyyy-MM-dd"/>
                            <span class="input-group-addon">到</span>
                            <input type="text" class="input-sm form-control" id="actualRentEndTimeEnd" name="actualRentEndTimeEnd" autocomplete="off" placeholder="yyyy-MM-dd"/>
                        </div>
                    </div>
                    <div class="form-group  col-lg-4">
                        <label class="control-label col-sm-4">计划租赁天数:</label>
                        <div class="input-group">
                            <input type="number" name="planRentSpanStart" class="form-control" autocomplete="off"/>
                            <span class="input-group-addon">到</span>
                            <input type="number" name="planRentSpanEnd"  class="form-control" autocomplete="off"/>
                        </div>
                    </div>
                    <div class="form-group  col-lg-4">
                        <label class="control-label col-sm-4">实际租赁天数:</label>
                        <div class="input-group input-daterange">
                            <input type="number" name="actualRentSpanStart" class="form-control"  autocomplete="off"/>
                            <span class="input-group-addon">到</span>
                            <input type="number" name="actualRentSpanEnd" class="form-control"  autocomplete="off"/>
                        </div>
                    </div>
                    <div class="form-group   col-lg-4">
                        <label class="control-label col-sm-4">备注:</label>
                        <div class="input-group">
                            <input type="text" name="note" class="form-control col-sm-4"   autocomplete="off"/>
                        </div>
                    </div>
                    <div class="form-group  col-lg-4">
                        <label class="control-label col-sm-4">有效性:</label>
                        <div class="input-group">
                            <select name="valid" class="form-control col-sm-4" th:with="type=${@dict.getType('sys_rent_valid')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group  col-lg-4">
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:rent:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:rent:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.detail()">
                    <i class="fa fa-edit"></i> 打印单据
                </a>
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:rent:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:rent:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-suggest-js" />
    <th:block th:include="include :: bootstrap-typeahead-js" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:rent:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:rent:remove')}]];
        var prefix = ctx + "system/rent";
        var rentValidDatas = [[${@dict.getType('sys_rent_valid')}]];
        var unitDatas = [[${@dict.getType('sys_unit')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/gotoPrintRentInfo/{id}",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                modalName: "出库单",
                columns: [{
                    radio: true
                },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },{
                        field: 'rentNumber',
                        title: '出库单号'
                    },{
                    field: 'customerName',
                    title: '客户名称'
                },{
                        field: 'customerContacts',
                        title: '联系人'
                    },{
                    field: 'customerPhone',
                    title: '客户手机号'
                },{
                    field: 'customerAddress',
                    title: '客户地址'
                },{
                    field: 'customerIdCard',
                    title: '客户身份证号'
                },{
                        field: 'customerTel',
                        title: '客户座机号'
                    },{
                    field: 'issueTime',
                    title: '出单时间'
                },
                {
                    field: 'planRentStartTime',
                    title: '计划租赁开始日期时间'
                },
                {
                    field: 'actualRentStartTime',
                    title: '实际租赁开始日期时间'
                },
                {
                    field: 'planRentEndTime',
                    title: '计划租赁结束时间'
                },
                {
                    field: 'actualRentEndTime',
                    title: '实际租赁结束时间'
                },
                {
                    field: 'planRentSpan',
                    title: '计划租赁天数'
                },
                {
                    field: 'actualRentSpan',
                    title: '实际租赁天数'
                },
                {
                    field: 'note',
                    title: '备注'
                },
                {
                    field: 'valid',
                    title: '状态',
                    formatter:function (value,row,index){
                        return $.table.selectDictLabel(rentValidDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }, {
                    field: 'createTime',
                    title: '创建时间'
                },{
                    field: 'updateTime',
                    title: '最近更新时间'
                  }
                ]
            };
            $.table.init(options);
        });
        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: ctx + "system/link/list",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    rentId: row.id
                },
                columns: [{
                    field : 'typeName',
                    title : '器材类型名称'
                },
                    {
                        field : 'modeName',
                        title : '器材型号'
                    }
                    // ,{
                    //     field: 'unit',
                    //     title: '单位',
                    //     formatter:function (value,row,index){
                    //         return $.table.selectDictLabel(unitDatas, value);
                    //     }
                    // }
                    ,
                    {
                        field : 'deviceSerialNumber',
                        title : '器材编号'
                    },
                    {
                        field : 'deviceNote',
                        title : '器材备注'
                    },
                    {
                        field: 'planRentStartTime',
                        title: '计划租赁开始日期时间'
                    },
                    {
                        field: 'actualRentStartTime',
                        title: '实际租赁开始日期时间'
                    },
                    {
                        field: 'planRentEndTime',
                        title: '计划租赁结束时间'
                    },
                    {
                        field: 'actualRentEndTime',
                        title: '实际租赁结束时间'
                    },
                    {
                        field: 'planRentSpan',
                        title: '计划租赁天数'
                    },
                    {
                        field: 'actualRentSpan',
                        title: '实际租赁天数'
                    },
                    {
                        field: 'note',
                        title: '备注'
                    },
                    {
                        field: 'valid',
                        title: '状态',
                        formatter:function (value,row,index){
                            return $.table.selectDictLabel(rentValidDatas, value);
                        }
                    },{
                        field: 'createTime',
                        title: '创建时间'
                    },{
                        field: 'updateTime',
                        title: '最近更新时间'
                    }
                    ]
            });
        };
        var testBsSuggest = $("#searchCustomer").bsSuggest({
            allowNoKeyword: false, //是否允许无关键字时请求数据
            multiWord: false, //以分隔符号分割的多关键字支持
            url: "http://"+window.location.host + "/system/customer/queryValidCustomerByParam?param=",
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            effectiveFields: ["id","name", "address", "tel", "phone", "idCard"],
            searchFields: [ "name", "address", "tel", "phone", "idCard"],
            effectiveFieldsAlias:{name: "姓名",address:"地址",tel:"座机号",phone:"手机号", idCard:"身份证号"},
            clearable: true,
            idField: "id",
            keyField: "name"
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
            console.log('onSetSelectValue: ', keyword);
            $("#customerId").val(keyword.id);
        }).on('onUnsetSelectValue', function (e) {
            $("#customerId").val(0);
        });
        //出单时间
        $("#issueTimeStart").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var startTime = event.date;
            $('#issueTimeEnd').datetimepicker('setStartDate', startTime);
        });

        $("#issueTimeEnd").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var endTime = event.date;
            $("#issueTimeStart").datetimepicker('setEndDate', endTime);
        });
        //计划开始租赁时间
        $("#planRentStartTimeStart").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var startTime = event.date;
            $('#planRentStartTimeEnd').datetimepicker('setStartDate', startTime);
        });

        $("#planRentStartTimeEnd").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var endTime = event.date;
            $("#planRentStartTimeStart").datetimepicker('setEndDate', endTime);
        });
        //计划结束租赁时间
        $("#planRentEndTimeStart").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var startTime = event.date;
            $('#planRentEndTimeEnd').datetimepicker('setStartDate', startTime);
        });

        $("#planRentEndTimeEnd").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var endTime = event.date;
            $("#planRentEndTimeStart").datetimepicker('setEndDate', endTime);
        });
        //实际开始租赁时间
        $("#actualRentStartTimeStart").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var startTime = event.date;
            $('#actualRentStartTimeEnd').datetimepicker('setStartDate', startTime);
        });

        $("#actualRentStartTimeEnd").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var endTime = event.date;
            $("#actualRentStartTimeStart").datetimepicker('setEndDate', endTime);
        });
        //实际结束租赁时间
        $("#actualRentEndTimeStart").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var startTime = event.date;
            $('#actualRentEndTimeEnd').datetimepicker('setStartDate', startTime);
        });

        $("#actualRentEndTimeEnd").datetimepicker({
            format: 'yyyy-mm-dd',
            minView: "month",
            todayBtn:  true,
            autoclose: true,
            // endDate : new Date(),
        }).on('changeDate', function(event) {
            event.preventDefault();
            event.stopPropagation();
            var endTime = event.date;
            $("#actualRentEndTimeStart").datetimepicker('setEndDate', endTime);
        });
        //打印单据
        function printRentInfo(){
            //选择id
            table.set();
            $.modal.openTab("单元单据", prefix+"/getRentInfo/"+id);
        }
    </script>
</body>
</html>